<?php
if (!session_id()) {
    session_start();
}
$user_id = $_SESSION['user_id'];

global $wpdb;
$tb_img = 'ap_painting_img';
$tb_user = 'ap_painting_user';
?>
<?php
// if detail album 
if (isset($_GET['detail']) && $_GET['detail']) {
    $offset = 10;

    $userid = $_GET['detail'];

    $total = $wpdb->get_results("SELECT * FROM $tb_img WHERE user_id ={$userid}");
    $album = $wpdb->get_results("SELECT *, $tb_img.id as img_id FROM $tb_img LEFT JOIN $tb_user ON $tb_img.user_id = $tb_user.user_id WHERE $tb_img.user_id ={$userid} ORDER BY dateadd DESC"); 
    $flag = false;
    ?>
    <script type="text/javascript">
        jQuery(document).ready(function() {
            jQuery("a[rel^='prettyPhoto']").prettyPhoto({
                default_width: 600,
                default_height: 400,
            });
        });
    </script>

	<?php if(count($album)){ ?>
    <ul class="gallery album">


        <?php  
            foreach ($album as $k => $row) {

                $xname = substr( $row->url, 0, strpos($row->url, ".png"));
					$xrand = rand(1,4);
                ?>
                <li>
                    <a href="<?php echo $xname."-600.png" ?>" rel="prettyPhoto[]" >
                        <img  class="xthumb<?php echo $xrand ?>"  class="<?php echo $flag ? '' : 'thumb'; ?>" src="<?php echo $xname."-min.png" ?>">
                        <div class="boxhover<?php echo $xrand ?>"><img src="<?php echo bloginfo('template_url'); ?>/img/xthumb_<?php echo $xrand ?>.png" /></div>
                    </a>
                </li>
				

            <?php } ?>

    </ul>
	<?php } ?>



    <?php
} else {  // GET ALL ALBUM OF ALL USER  
// GET HEADER  
    get_header();
    ?>
	
<script type="text/javascript">

    function loadfimg($albumid) {
        $.blockUI({css: {
                border: 'none',
                padding: '15px',
                backgroundColor: '#000',
                '-webkit-border-radius': '10px',
                '-moz-border-radius': '10px',
                opacity: .5,
                color: '#fff'
            }});
        jQuery.post("<?php echo site_url('/') ?>album/?detail=" + $albumid, function($data) {
            jQuery('#albumfuck').html($data);
            $.unblockUI();

        });
    }
</script>
    <script type="text/javascript" src="<?php echo bloginfo('template_url'); ?>/js/jquery.prettyPhoto.js"></script>
    <link href="<?php echo bloginfo('template_url'); ?>/css/prettyPhoto.css" type="text/css" rel="stylesheet" />

    <div class="album_baithi">

        <?php
        global $wpdb;

        $tb_img = 'ap_painting_img';

        $tb_user = 'ap_painting_user';

        $total = $wpdb->get_results("SELECT * FROM $tb_img 
            LEFT JOIN $tb_user ON $tb_img.user_id = $tb_user.user_id 
            GROUP BY $tb_img.user_id");

        $owneralbum = $wpdb->get_row("SELECT * FROM $tb_img LEFT JOIN $tb_user ON $tb_img.user_id = $tb_user.user_id WHERE  $tb_user.user_id = {$user_id} ");

        $album = $wpdb->get_results("SELECT * FROM $tb_img LEFT JOIN $tb_user ON $tb_img.user_id = $tb_user.user_id  WHERE  $tb_user.user_id != {$user_id} GROUP BY $tb_img.user_id");

        $flag = true;
        ?>
        <div class="close-btn">
            <a href="<?php echo site_url() ?>"><img src="<?php echo bloginfo('template_url'); ?>/img/btn-close.png"></a>
        </div>
        <div id="albumfuck"> 
			<div class="gttuan"><p><img src="<?php echo bloginfo('template_url'); ?>/img/gia_thuong_tuan.png" /></p>
			<ul>
				<li>&nbsp;</li>
				<li>&nbsp;</li>
				<li>&nbsp;</li>
				<li>&nbsp;</li>
			</ul>
			</div>
			<div style="clear:both"></div> <br />
			<div class="albumtele"><img src="<?php echo bloginfo('template_url'); ?>/img/album_thiep.png" /></div>
            <ul id="exam_<?php echo $pagex ?>" class="gallery <?php echo (!$pagex && !$currpage) || $currpage ? '' : 'hide' ?>" >
                <?php
                $row = $owneralbum;
                $thumimg = $wpdb->get_row("SELECT * FROM $tb_img WHERE user_id = $row->user_id ORDER BY dateadd DESC LIMIT 1");
				$xname = substr( $thumimg->url, 0, strpos($thumimg->url, ".png"));
				if($thumimg->id){
					$xrand = rand(1,4);
                ?>
                <li onclick="loadfimg(<?php echo $row->user_id ?>)">
					
                    <img class="xthumb<?php echo $xrand ?>" src="<?php echo $xname."-600.png" ?>">
					<div class="boxhover<?php echo $xrand ?>"><img src="<?php echo bloginfo('template_url'); ?>/img/xthumb_<?php echo $xrand ?>.png" /></div>
                    <p class="user x<?php echo $xrand ?>">
                        <a href="javascript:void(0)" >
                            <?php echo $row->name ?>
                        </a>
                    </p>

                </li>
                <?php
				}
                foreach ($album as $k => $row) {
                    $thumimg = $wpdb->get_row("SELECT * FROM $tb_img WHERE user_id = $row->user_id ORDER BY dateadd DESC LIMIT 1");
                    list($d, $m, $y) = explode("-", $row->birthday);
                    $old = 2013 - $y;
									$xname = substr( $row->url, 0, strpos($row->url, ".png"));
														$xrand = rand(1,4);

                    ?>
                    <li  onclick="loadfimg(<?php echo $row->user_id ?>)"  >
                    <img class="xthumb<?php echo $xrand ?>" src="<?php echo $xname."-600.png" ?>">
					<div class="boxhover<?php echo $xrand ?>"><img src="<?php echo bloginfo('template_url'); ?>/img/xthumb_<?php echo $xrand ?>.png" /></div>
                    <p class="user x<?php echo $xrand ?>">
                        <a href="javascript:void(0)" >
                            <?php echo $row->name ?>
                        </a>
                    </p>

                    </li>

                <?php } ?>

            </ul>
        </div>
        <div class="tt-control" style="padding-left: 150px; ">
            <a href="<?php echo home_url('tao-thiep') ?>"><img src="<?php echo bloginfo('template_url'); ?>/img/btn-choilai.png" /></a>
            <a href="<?php echo home_url('album') ?>"><img src="<?php echo bloginfo('template_url'); ?>/img/btn-album.png" /></a>
        </div>
    </div>
    <script type="text/javascript">
        jQuery(document).ready(function() {
            jQuery('#albumfuck').slimscroll({
                width: '900px',
                height: '570px',
                railVisible: true,
                alwaysVisible: true,
                railColor: '#fff',
                opacity: 0.7,
                color: '#eee'
            });
        });
    </script>
	
<div class="music">
    <a href="javascript:;" class="volumn"><img src="<?php echo bloginfo('template_url'); ?>/img/vol-on.png"></a>
    <!--  <span class="songname">Last Christmas ...</span> --> 
     <div id="songhere"></div>
</div>
	<script type="text/javascript">
    var music = '<EMBED src="https://www.vietbuzzad.net/triumphecard/lastchristmas.mp3" hidden="true" id="musicplayer" autostart="true" loop="infinite" height=0 width=0></EMBED>';
        // var status = getCookie("music"); 
        <?php if(isset($_SESSION['music'])&&$_SESSION['music']=='false'){ ?>
            $('.volumn').addClass('off');
            $('.volumn').find('img').attr('src','<?php echo bloginfo('template_url'); ?>/img/vol-off.png');
        <?php }else{ ?>
            $('#songhere').html(music);
            $('.volumn').removeClass('off');
            $('.volumn').find('img').attr('src','<?php echo bloginfo('template_url'); ?>/img/vol-on.png');
        <?php } ?>
        
        $('.volumn').live('click',function(){
            if(!$(this).hasClass('off')){
                $(this).addClass('off');
                $(this).find('img').attr('src','<?php echo bloginfo('template_url'); ?>/img/vol-off.png');
                $('#songhere').html('');
                setSession(false);
                // setCookie('music','disable');
            }else{
                $(this).removeClass('off');
                $(this).find('img').attr('src','<?php echo bloginfo('template_url'); ?>/img/vol-on.png');
                $('#songhere').html(music);
                setSession(true);
                // setCookie('music','enable');
            }
        });
    //$('.volumn').click();
</script>
    <?php get_footer() ?>

<?php } ?>

